﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.IO;

using Museum.DBAccess;

/// <summary>
/// Summary description for Utility
/// </summary>
public class XMLResponse
{
    private static string virtualDirectoryPath = ConfigurationSettings.AppSettings["ServerURL"].ToString();
    private static string defaultImagePath = ConfigurationSettings.AppSettings["DefaultImagePath"].ToString();

    #region "Constructor"
    public XMLResponse()
    {

    }
    #endregion

    #region " For Invalid Input parameters "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForInvalidInputParameter()
    {
        StringWriter stringWriter = new StringWriter();
        try
        {

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();
            xmlTextWriter.WriteStartElement("Response");
            xmlTextWriter.WriteElementString("Error", "Invalid Input Parameters");
            xmlTextWriter.WriteEndElement(); // end score

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Museym By City "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForMuseumByCity(string cityName)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtMuseumDetails = null;
        try
        {
            dtMuseumDetails = new DataTable();
            dtMuseumDetails = DBAccess.GetMuseumByCity(cityName);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtMuseumDetails.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Museum");

                // Museum ID
                xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                // Museum Name
                xmlTextWriter.WriteElementString("MuseumName", dtRow["MuseumName"].ToString());

                // Museum Address
                xmlTextWriter.WriteElementString("MuseumAddress", dtRow["MuseumAddress"].ToString());

                // Museum Info
                xmlTextWriter.WriteElementString("MuseumInfo", dtRow["MuseumInfo"].ToString());

                // City Id
                xmlTextWriter.WriteElementString("CityId", dtRow["CityId"].ToString());

                // IsPartner
                xmlTextWriter.WriteElementString("IsPartner", dtRow["IsPartner"].ToString());

                // MuseumRating
                xmlTextWriter.WriteElementString("MuseumRating", dtRow["MuseumRating"].ToString());

                // MuseumLink
                xmlTextWriter.WriteElementString("MuseumLink", dtRow["MuseumLink"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                #endregion

                xmlTextWriter.WriteEndElement();
            }
            xmlTextWriter.WriteEndElement(); // end Articles

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Voucher Status "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForVoucherStatus(string voucher, int gameId)
    {
        StringWriter stringWriter = new StringWriter();
        string VoucherStatus = string.Empty;
        try
        {
            VoucherStatus = DBAccess.GetVoucherStatus(voucher, gameId);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            // Voucher Status
            if (VoucherStatus.Equals("Voucher accepted"))
                xmlTextWriter.WriteElementString("VoucherStatus", "1");
            else if (VoucherStatus.Equals("Voucher expired"))
                xmlTextWriter.WriteElementString("VoucherStatus", "0");
            else if (VoucherStatus.Equals("Voucher invalid"))
                xmlTextWriter.WriteElementString("VoucherStatus", "0");

            xmlTextWriter.WriteEndElement(); // end Articles

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Game By Museum "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForGameByMuseum(int museumId)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameDetails = null;
        try
        {
            dtGameDetails = new DataTable();
            dtGameDetails = DBAccess.GetGameByMuseum(museumId);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameDetails.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Game");

                // Museum ID
                xmlTextWriter.WriteElementString("GameId", dtRow["GameId"].ToString());

                // Treasure Id
                xmlTextWriter.WriteElementString("TreasureId", dtRow["TreasureId"].ToString());

                // Game Alias
                xmlTextWriter.WriteElementString("GameAlias", dtRow["GameAlias"].ToString());

                // Game Type
                xmlTextWriter.WriteElementString("GameType", dtRow["GameType"].ToString());

                // Game Name
                xmlTextWriter.WriteElementString("GameName", dtRow["GameName"].ToString());

                // Game Description
                xmlTextWriter.WriteElementString("GameDescription", dtRow["GameDescription"].ToString());

                // Expiry Date
                xmlTextWriter.WriteElementString("ExpiryDate", dtRow["ExpiryDate"].ToString());

                // IsActive
                xmlTextWriter.WriteElementString("IsActive", dtRow["IsActive"].ToString());

                // Game Level
                xmlTextWriter.WriteElementString("GameLevel", dtRow["GameLevel"].ToString());

                // Game Rating
                xmlTextWriter.WriteElementString("GameRating", dtRow["GameRating"].ToString());

                // Game Price
                xmlTextWriter.WriteElementString("GamePrice", dtRow["GamePrice"].ToString());

                // Game Version
                xmlTextWriter.WriteElementString("GameVersion", dtRow["GameVersion"].ToString());

                // Game Duration
                xmlTextWriter.WriteElementString("GameDuration", dtRow["GameDuration"].ToString());

                // Game Thumbnail Path
                xmlTextWriter.WriteElementString("GameThumbnailPath", dtRow["GameThumbnailPath"].ToString().Contains("http://") ? dtRow["GameThumbnailPath"].ToString() : virtualDirectoryPath + dtRow["GameThumbnailPath"].ToString());

                // Game app link
                xmlTextWriter.WriteElementString("AppLink", dtRow["AppLink"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                #endregion

                xmlTextWriter.WriteEndElement();
            }
            xmlTextWriter.WriteEndElement(); // end Articles

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Game By GameId "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForGameByGameId(int gameId, int isFirstTimeDownload, int requestingDevice)
    {
        StringWriter stringWriter = new StringWriter();
        DataSet dsGameDetails = null;
        try
        {
            dsGameDetails = new DataSet();
            dsGameDetails = DBAccess.GetGameByGameId(gameId, isFirstTimeDownload, requestingDevice);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            #region "Game Response"
            xmlTextWriter.WriteStartElement("Response");
            foreach (DataTable dt in dsGameDetails.Tables)
            {
                switch (dt.TableName.ToLower())
                {
                    case "game":
                        xmlTextWriter.WriteStartElement("Game");
                        foreach (DataRow dtRow in dt.Rows)
                        {
                            #region XMLResponse

                            // GameId
                            xmlTextWriter.WriteElementString("GameId", dtRow["GameId"].ToString());

                            // GameType
                            xmlTextWriter.WriteElementString("GameType", dtRow["GameType"].ToString());

                            // GameAlias
                            xmlTextWriter.WriteElementString("GameAlias", dtRow["GameAlias"].ToString());

                            // Treasure Id
                            xmlTextWriter.WriteElementString("TreasureId", dtRow["TreasureId"].ToString());

                            // Game Name
                            xmlTextWriter.WriteElementString("GameName", dtRow["GameName"].ToString());

                            // Game Description
                            xmlTextWriter.WriteElementString("GameDescription", dtRow["GameDescription"].ToString());

                            // Expiry Date
                            xmlTextWriter.WriteElementString("ExpiryDate", dtRow["ExpiryDate"].ToString());

                            // IsActive
                            xmlTextWriter.WriteElementString("IsActive", dtRow["IsActive"].ToString());

                            // Game Level
                            xmlTextWriter.WriteElementString("GameLevel", dtRow["GameLevel"].ToString());

                            // Game Rating
                            xmlTextWriter.WriteElementString("GameRating", dtRow["GameRating"].ToString());

                            // Game Price
                            xmlTextWriter.WriteElementString("GamePrice", dtRow["GameLevel"].ToString());

                            // Game Version
                            xmlTextWriter.WriteElementString("GameVersion", dtRow["GameVersion"].ToString());

                            // Game Duration
                            xmlTextWriter.WriteElementString("GameDuration", dtRow["GameDuration"].ToString());

                            // Game Thumbnail Path
                            xmlTextWriter.WriteElementString("GameThumbnailPath", dtRow["GameThumbnailPath"].ToString().Contains("http://") ? dtRow["GameThumbnailPath"].ToString() : virtualDirectoryPath + dtRow["GameThumbnailPath"].ToString());

                            // Game app link
                            xmlTextWriter.WriteElementString("AppLink", dtRow["AppLink"].ToString());

                            // PitStopsCount
                            xmlTextWriter.WriteElementString("PitStopsCount", dtRow["ClueCount"].ToString());

                            // Created Date
                            xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                            #endregion
                        }
                        xmlTextWriter.WriteEndElement();
                        break;
                    //case "assets":
                    //    xmlTextWriter.WriteStartElement("GameAssets");
                    //    foreach (DataRow dtRow in dt.Rows)
                    //    {
                    //        #region XMLResponse

                    //        xmlTextWriter.WriteStartElement("Assets");

                    //        // GameAssetId
                    //        xmlTextWriter.WriteElementString("GameAssetsId", dtRow["GameAssetsId"].ToString());

                    //        // Game ID
                    //        xmlTextWriter.WriteElementString("GameId", dtRow["GameId"].ToString());

                    //        // IsAudio
                    //        xmlTextWriter.WriteElementString("IsAudio", dtRow["IsAudio"].ToString());

                    //        // IsVideo
                    //        xmlTextWriter.WriteElementString("IsVideo", dtRow["IsVideo"].ToString());

                    //        // IsImage
                    //        xmlTextWriter.WriteElementString("IsImage", dtRow["IsImage"].ToString());

                    //        // FilePath
                    //        xmlTextWriter.WriteElementString("FilePath", dtRow["FilePath"].ToString().Contains("http://") ? dtRow["FilePath"].ToString() : virtualDirectoryPath + dtRow["FilePath"].ToString());

                    //        // Created Date
                    //        xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                    //        xmlTextWriter.WriteEndElement();

                    //        #endregion
                    //    }
                    //    xmlTextWriter.WriteEndElement();
                    //    break;
                    case "treasure":
                        xmlTextWriter.WriteStartElement("Treasure");
                        foreach (DataRow dtRow in dt.Rows)
                        {
                            #region XMLResponse

                            xmlTextWriter.WriteStartElement("TreasureDetails");

                            // Treasure Id
                            xmlTextWriter.WriteElementString("TreasureId", dtRow["TreasureId"].ToString());

                            // Museum Id
                            xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                            // Treasure Name
                            xmlTextWriter.WriteElementString("TreasureName", dtRow["TreasureName"].ToString());

                            // Treasure Image Path
                            xmlTextWriter.WriteElementString("TreasureImagePath", dtRow["TreasureImagePath"].ToString().Contains("http://") || string.IsNullOrEmpty(dtRow["TreasureImagePath"].ToString()) ? dtRow["TreasureImagePath"].ToString() : virtualDirectoryPath + dtRow["TreasureImagePath"].ToString());

                            // Treasure Location
                            xmlTextWriter.WriteElementString("TreasureLocation", dtRow["TreasureLocation"].ToString());

                            // Treasure Details
                            xmlTextWriter.WriteElementString("TreasureAdditionalInfo", dtRow["TreasureDetails"].ToString());

                            // Final Question
                            xmlTextWriter.WriteElementString("FinalQuestion", dtRow["FinalQuestion"].ToString());

                            // Final Answer
                            xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                            // Final Clue
                            xmlTextWriter.WriteElementString("FinalClue", dtRow["FinalClue"].ToString());

                            // Created Date
                            xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                            xmlTextWriter.WriteEndElement();

                            #endregion
                        }
                        xmlTextWriter.WriteEndElement();
                        break;
                    case "clue":
                        xmlTextWriter.WriteStartElement("GameClues");
                        foreach (DataRow dtRow in dt.Rows)
                        {
                            #region XMLResponse
                            xmlTextWriter.WriteStartElement("Clue");

                            // ClueId
                            xmlTextWriter.WriteElementString("ClueId", dtRow["ClueId"].ToString());

                            // Game ID
                            xmlTextWriter.WriteElementString("GameId", dtRow["GameId"].ToString());

                            // ClueDetail
                            xmlTextWriter.WriteElementString("ClueDetail", dtRow["ClueDetail"].ToString());

                            // Direction
                            xmlTextWriter.WriteElementString("DirectionDetails", dtRow["DirectionDetails"].ToString());

                            // ClueSequence
                            xmlTextWriter.WriteElementString("ClueSequence", dtRow["ClueSequence"].ToString());

                            //LocateArt
                            xmlTextWriter.WriteElementString("LocateArt", dtRow["LocateArt"].ToString());

                            //FindWordAt
                            xmlTextWriter.WriteElementString("FindWordAt", dtRow["FindWordAt"].ToString());

                            //Answer
                            xmlTextWriter.WriteElementString("Answer", dtRow["Answer"].ToString());

                            //IsCritical
                            xmlTextWriter.WriteElementString("IsCritical", dtRow["IsCritical"].ToString());

                            //FileType
                            xmlTextWriter.WriteElementString("FileType", dtRow["Type"].ToString());

                            //FilePath
                            xmlTextWriter.WriteElementString("FilePath", dtRow["FilePath"].ToString().Contains("http://") || string.IsNullOrEmpty(dtRow["FilePath"].ToString()) ? dtRow["FilePath"].ToString() : virtualDirectoryPath + dtRow["FilePath"].ToString());

                            xmlTextWriter.WriteStartElement("GameHints");
                            foreach (DataRow dtHintRow in dsGameDetails.Tables["Hint"].Rows)
                            {
                                #region Hints

                                if (dtRow["ClueId"].ToString().Trim().Equals(dtHintRow["ClueId"].ToString().Trim()))
                                {
                                    xmlTextWriter.WriteStartElement("Hint");

                                    // HintId
                                    xmlTextWriter.WriteElementString("HintId", dtHintRow["HintId"].ToString());

                                    // Clue ID
                                    xmlTextWriter.WriteElementString("ClueId", dtHintRow["ClueId"].ToString());

                                    // HintDescription
                                    xmlTextWriter.WriteElementString("HintDescription", dtHintRow["HintDescription"].ToString());

                                    // IsAnswer
                                    xmlTextWriter.WriteElementString("IsAnswer", dtHintRow["IsAnswer"].ToString());

                                    xmlTextWriter.WriteEndElement();
                                }

                                #endregion
                            }
                            xmlTextWriter.WriteEndElement();

                            xmlTextWriter.WriteEndElement();

                            #endregion
                        }
                        xmlTextWriter.WriteEndElement();
                        break;
                }
            }
            xmlTextWriter.WriteEndElement(); // end Game 
            #endregion

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Game Update "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="gameId"></param>
    /// <param name="version"></param>
    /// <returns></returns>
    public static string ForGameUpdate(int gameId, int version)
    {
        StringWriter stringWriter = new StringWriter();
        bool isUpdateAvailable = false;
        try
        {
            isUpdateAvailable = DBAccess.GetGameUpdate(gameId, version);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");
            if (isUpdateAvailable)
            {
                xmlTextWriter.WriteElementString("Updates", "1");
            }
            else
            {
                xmlTextWriter.WriteElementString("Updates", "0");
            }
            xmlTextWriter.WriteEndElement(); // end Articles

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Game Top Score "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForGameTopScore(int count, int gameId)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameScore = null;
        try
        {
            dtGameScore = new DataTable();
            dtGameScore = DBAccess.GetTopGameScore(count, gameId);


            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameScore.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("GameScore");

                // Game Score Id
                xmlTextWriter.WriteElementString("GameScoreId", dtRow["GameScoreId"].ToString());

                // Game Id
                xmlTextWriter.WriteElementString("GameId", dtRow["GameId"].ToString());

                // User Name
                xmlTextWriter.WriteElementString("UserName", dtRow["UserName"].ToString());

                // Score
                xmlTextWriter.WriteElementString("Score", dtRow["Score"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                #endregion

                xmlTextWriter.WriteEndElement();
            }
            xmlTextWriter.WriteEndElement(); // end score

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Submmit Game Score "
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForSubmitGameScore(int gameId, string userName, int score)
    {
        StringWriter stringWriter = new StringWriter();
        int inserted = 0;
        try
        {
            inserted = DBAccess.InsertGameScore(gameId, userName, score);


            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            #region XMLResponse

            xmlTextWriter.WriteStartElement("GameScore");

            // Game Score Insert Status
            xmlTextWriter.WriteElementString("InsertStatus", inserted == -1 ? "Success" : "Failure");

            #endregion

            xmlTextWriter.WriteEndElement();

            xmlTextWriter.WriteEndElement(); // end score

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Submmit Reveiw"
    /// <summary>
    /// 
    /// </summary>
    /// <param name="cityName"></param>
    /// <returns></returns>
    public static string ForSubmitReview(int gameId, string review, string userName, short rating)
    {
        StringWriter stringWriter = new StringWriter();
        int inserted = 0;
        try
        {
            inserted = DBAccess.InsertGameReview(gameId, review, userName, rating);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            #region XMLResponse

            xmlTextWriter.WriteStartElement("GameReview");

            // Game Score Insert Status
            xmlTextWriter.WriteElementString("InsertStatus", inserted == -1 ? "Success" : "Failure");

            #endregion

            xmlTextWriter.WriteEndElement();

            xmlTextWriter.WriteEndElement(); // end score

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Categories "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForCategories(int MuseumId)
    {
        StringWriter stringWriter = new StringWriter();
        DataSet dsGameScore = null;
        try
        {
            dsGameScore = new DataSet();
            dsGameScore = DBAccess.GetCategories(MuseumId);


            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dsGameScore.Tables["Categories"].Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // Category Id
                xmlTextWriter.WriteElementString("CategoryId", dtRow["CategoryId"].ToString());

                // Category Name
                xmlTextWriter.WriteElementString("CategoryName", dtRow["CategoryName"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion

            }

            foreach (DataRow dtRow in dsGameScore.Tables["SearchColumns"].Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("SearchColumns");

                // ArtName
                xmlTextWriter.WriteElementString("ArtName", dtRow["ArtName"].ToString());

                // ArtistName
                xmlTextWriter.WriteElementString("ArtistName", dtRow["ArtistName"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("StopNumber", dtRow["StopNumber"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("FloorNumber", dtRow["FloorNumber"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("Gallery", dtRow["Gallery"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion

            }
            xmlTextWriter.WriteEndElement(); // end Category

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Reviews "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForReviews(int GameId)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameScore = null;
        try
        {
            dtGameScore = new DataTable();
            dtGameScore = DBAccess.GetReviews(GameId);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameScore.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Reviews");

                // Category Id
                xmlTextWriter.WriteElementString("UserName", dtRow["UserName"].ToString());

                // Review Comments
                xmlTextWriter.WriteElementString("ReviewComments", dtRow["ReviewComments"].ToString());

                // Game Rating
                xmlTextWriter.WriteElementString("GameRating", dtRow["GameRating"].ToString());

                // Ratings
                xmlTextWriter.WriteElementString("ReviewRatings", dtRow["ReviewRatings"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                #endregion

                xmlTextWriter.WriteEndElement();
            }
            xmlTextWriter.WriteEndElement(); // end Review

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Search Art "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForSearchArt(string searchString, string searchInColumnName, int categoryId, int museumId, int fromIndex, int count)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameScore = null;
        try
        {
            dtGameScore = new DataTable();
            dtGameScore = DBAccess.GetSearchArt(searchString, searchInColumnName, categoryId, museumId, fromIndex, count);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameScore.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // Art Id
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // Category Id
                xmlTextWriter.WriteElementString("CategoryId", dtRow["CategoryId"].ToString());

                // CategoryMapping Id
                xmlTextWriter.WriteElementString("CategoryMappingId", dtRow["CategoryMappingId"].ToString());

                // Museum Id
                xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                // Category Name
                xmlTextWriter.WriteElementString("CategoryName", dtRow["CategoryName"].ToString());

                // ArtName
                xmlTextWriter.WriteElementString("ArtName", dtRow["ArtName"].ToString());

                // ArtDescription
                xmlTextWriter.WriteElementString("ArtDescription", dtRow["ArtDescription"].ToString());

                // Artist Name
                xmlTextWriter.WriteElementString("ArtistName", dtRow["ArtistName"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("StopNumber", dtRow["StopNumber"].ToString());

                // Floor Number
                xmlTextWriter.WriteElementString("FloorNumber", dtRow["FloorNumber"].ToString());

                // Gallery
                xmlTextWriter.WriteElementString("Gallery", dtRow["Gallery"].ToString());

                // Final Question
                xmlTextWriter.WriteElementString("FinalTreasureAdditionalInfo", dtRow["FinalQuestion"].ToString());

                // Final Answer
                xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                // Critical Word
                xmlTextWriter.WriteElementString("CriticalWord", dtRow["CriticalWord"].ToString());

                // Art Image path
                xmlTextWriter.WriteElementString("ArtImagePath", dtRow["ArtImagePath"].ToString().Contains("http://") ? dtRow["ArtImagePath"].ToString() : virtualDirectoryPath + dtRow["ArtImagePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());
                #endregion

                xmlTextWriter.WriteEndElement();
            }

            xmlTextWriter.WriteEndElement(); // end Category

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Get Arts "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForGetArts(int categoryId, int fromIndex, int pageSize)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameScore = null;
        try
        {
            dtGameScore = new DataTable();
            dtGameScore = DBAccess.GetArts(categoryId, fromIndex, pageSize);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameScore.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // Art Id
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // Category Id
                xmlTextWriter.WriteElementString("CategoryId", dtRow["CategoryId"].ToString());

                // CategoryMapping Id
                xmlTextWriter.WriteElementString("CategoryMappingId", dtRow["CategoryMappingId"].ToString());

                // Museum Id
                xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                // Category Name
                xmlTextWriter.WriteElementString("CategoryName", dtRow["CategoryName"].ToString());

                // ArtName
                xmlTextWriter.WriteElementString("ArtName", dtRow["ArtName"].ToString());

                // ArtDescription
                xmlTextWriter.WriteElementString("ArtDescription", dtRow["ArtDescription"].ToString());

                // Artist Name
                xmlTextWriter.WriteElementString("ArtistName", dtRow["ArtistName"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("StopNumber", dtRow["StopNumber"].ToString());

                // Floor Number
                xmlTextWriter.WriteElementString("FloorNumber", dtRow["FloorNumber"].ToString());

                // Gallery
                xmlTextWriter.WriteElementString("Gallery", dtRow["Gallery"].ToString());

                //// Final Question
                //xmlTextWriter.WriteElementString("FinalQuestion", dtRow["FinalQuestion"].ToString());

                //// Final Answer
                //xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                //// Critical Word
                //xmlTextWriter.WriteElementString("CriticalWord", dtRow["CriticalWord"].ToString());

                // Art Image path
                xmlTextWriter.WriteElementString("ArtImagePath", dtRow["ArtImagePath"].ToString().Contains("http://") ? dtRow["ArtImagePath"].ToString() : virtualDirectoryPath + dtRow["ArtImagePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());
                #endregion

                xmlTextWriter.WriteEndElement();
            }

            xmlTextWriter.WriteEndElement(); // end Category

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Get City "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForGetCity(int countryId, DateTime updatedDate)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtCity = null;
        try
        {
            dtCity = new DataTable();
            dtCity = DBAccess.GetCity(countryId, updatedDate);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtCity.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // City Id
                xmlTextWriter.WriteElementString("CityId", dtRow["CityId"].ToString());

                // Country Id
                xmlTextWriter.WriteElementString("CountryId", dtRow["CountryId"].ToString());

                // Country Name
                xmlTextWriter.WriteElementString("CountryName", dtRow["CountryName"].ToString());

                // city Name
                xmlTextWriter.WriteElementString("CityName", dtRow["CityName"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("UpdatedDate", dtRow["CreatedDate"].ToString());

                #endregion

                xmlTextWriter.WriteEndElement();
            }

            xmlTextWriter.WriteEndElement(); // end Category

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion


    #region " For Get Art Details "
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static string ForGetArtDetails(int artId)
    {
        StringWriter stringWriter = new StringWriter();
        DataSet dsArt = null;
        try
        {
            dsArt = new DataSet();
            dsArt = DBAccess.GetArtDetails(artId);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dsArt.Tables["ArtMaster"].Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // Art Id
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // Category Id
                xmlTextWriter.WriteElementString("CategoryId", dtRow["CategoryId"].ToString());

                // CategoryMapping Id
                xmlTextWriter.WriteElementString("CategoryMappingId", dtRow["CategoryMappingId"].ToString());

                // Museum Id
                xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                // ArtName
                xmlTextWriter.WriteElementString("ArtName", dtRow["ArtName"].ToString());

                // ArtDescription
                xmlTextWriter.WriteElementString("ArtDescription", dtRow["ArtDescription"].ToString());

                // Artist Name
                xmlTextWriter.WriteElementString("ArtistName", dtRow["ArtistName"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("StopNumber", dtRow["StopNumber"].ToString());

                // Floor Number
                xmlTextWriter.WriteElementString("FloorNumber", dtRow["FloorNumber"].ToString());

                // Gallery
                xmlTextWriter.WriteElementString("Gallery", dtRow["Gallery"].ToString());

                //// Final Question
                //xmlTextWriter.WriteElementString("FinalQuestion", dtRow["FinalQuestion"].ToString());

                //// Final Answer
                //xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                //// Critical Word
                //xmlTextWriter.WriteElementString("CriticalWord", dtRow["CriticalWord"].ToString());

                // Art Image path
                xmlTextWriter.WriteElementString("ArtImagePath", dtRow["ArtImagePath"].ToString().Contains("http://") ? dtRow["ArtImagePath"].ToString() : virtualDirectoryPath + dtRow["ArtImagePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion
            }

            foreach (DataRow dtRow in dsArt.Tables["ArtAssets"].Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("ArtAssets");

                // ArtAssetId
                xmlTextWriter.WriteElementString("ArtAssetId", dtRow["ArtAssetId"].ToString());

                // ArtId
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // IsAudio
                xmlTextWriter.WriteElementString("IsAudio", dtRow["IsAudio"].ToString());

                // IsVideo
                xmlTextWriter.WriteElementString("IsVideo", dtRow["IsVideo"].ToString());

                // IsImage
                xmlTextWriter.WriteElementString("IsImage", dtRow["IsImage"].ToString());

                // FilePath
                xmlTextWriter.WriteElementString("FilePath", dtRow["FilePath"].ToString().Contains("http://") ? dtRow["FilePath"].ToString() : virtualDirectoryPath + dtRow["FilePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion
            }


            xmlTextWriter.WriteEndElement(); // end Category

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Tour Data"
    /// <summary>
    /// 
    /// </summary>
    /// <param name="categoryId"></param>
    /// <param name="fromIndex"></param>
    /// <param name="count"></param>
    /// <returns></returns>
    public static string ForTourData(int museumId, int fromIndex, int count)
    {
        StringWriter stringWriter = new StringWriter();
        DataSet dsTour = null;
        try
        {
            dsTour = new DataSet();
            dsTour = DBAccess.GetTourData(museumId, fromIndex, count);


            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dsTour.Tables["ArtMaster"].Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("Categories");

                // Art Id
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // CategoryMapping Id
                xmlTextWriter.WriteElementString("CategoryMappingId", dtRow["CategoryMappingId"].ToString());

                // ArtName
                xmlTextWriter.WriteElementString("ArtName", dtRow["ArtName"].ToString());

                // ArtDescription
                xmlTextWriter.WriteElementString("ArtDescription", dtRow["ArtDescription"].ToString());

                // Artist Name
                xmlTextWriter.WriteElementString("ArtistName", dtRow["ArtistName"].ToString());

                // StopNumber
                xmlTextWriter.WriteElementString("StopNumber", dtRow["StopNumber"].ToString());

                // Floor Number
                xmlTextWriter.WriteElementString("FloorNumber", dtRow["FloorNumber"].ToString());

                // Gallery
                xmlTextWriter.WriteElementString("Gallery", dtRow["Gallery"].ToString());

                // Final Question
                xmlTextWriter.WriteElementString("FinalQuestion", dtRow["FinalQuestion"].ToString());

                // Final Answer
                xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                // Critical Word
                xmlTextWriter.WriteElementString("CriticalWord", dtRow["CriticalWord"].ToString());

                // Art Image path
                xmlTextWriter.WriteElementString("ArtImagePath", dtRow["ArtImagePath"].ToString().Contains("http://") ? dtRow["ArtImagePath"].ToString() : virtualDirectoryPath + dtRow["ArtImagePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion

            }

            foreach (DataRow dtRow in dsTour.Tables["ArtAssets"].Rows)
            {

                #region XMLResponse

                xmlTextWriter.WriteStartElement("ArtAssets");

                // ArtAssetId
                xmlTextWriter.WriteElementString("ArtAssetId", dtRow["ArtAssetId"].ToString());

                // ArtId
                xmlTextWriter.WriteElementString("ArtId", dtRow["ArtId"].ToString());

                // IsAudio
                xmlTextWriter.WriteElementString("IsAudio", dtRow["IsAudio"].ToString());

                // IsVideo
                xmlTextWriter.WriteElementString("IsVideo", dtRow["IsVideo"].ToString());

                // IsImage
                xmlTextWriter.WriteElementString("IsImage", dtRow["IsImage"].ToString());

                // FilePath
                xmlTextWriter.WriteElementString("FilePath", dtRow["FilePath"].ToString().Contains("http://") ? dtRow["FilePath"].ToString() : virtualDirectoryPath + dtRow["FilePath"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion
            }
            xmlTextWriter.WriteEndElement(); // end Tour

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

    #region " For Treasure Details"
    /// <summary>
    /// 
    /// </summary>
    /// <param name="categoryId"></param>
    /// <param name="fromIndex"></param>
    /// <param name="count"></param>
    /// <returns></returns>
    public static string ForTreasureDetails(int treasureId)
    {
        StringWriter stringWriter = new StringWriter();
        DataTable dtGameScore = null;
        try
        {
            dtGameScore = new DataTable();
            dtGameScore = DBAccess.GetTreasureDetails(treasureId);


            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            xmlTextWriter.WriteStartDocument();

            xmlTextWriter.WriteStartElement("Response");

            foreach (DataRow dtRow in dtGameScore.Rows)
            {
                #region XMLResponse

                xmlTextWriter.WriteStartElement("TreasureDetails");

                // Treasure Id
                xmlTextWriter.WriteElementString("TreasureId", dtRow["TreasureId"].ToString());

                // Museum Id
                xmlTextWriter.WriteElementString("MuseumId", dtRow["MuseumId"].ToString());

                // Category Id
                xmlTextWriter.WriteElementString("CategoryId", dtRow["CategoryId"].ToString());

                // Treasure Name
                xmlTextWriter.WriteElementString("TreasureName", dtRow["TreasureName"].ToString());

                // Treasure Location
                xmlTextWriter.WriteElementString("TreasureLocation", dtRow["TreasureLocation"].ToString());

                // Treasure Details
                xmlTextWriter.WriteElementString("TreasureDetails", dtRow["TreasureDetails"].ToString());

                // Final Question
                xmlTextWriter.WriteElementString("FinalTreasureAdditionalInfo", dtRow["FinalQuestion"].ToString());

                // Final Answer
                xmlTextWriter.WriteElementString("FinalAnswer", dtRow["FinalAnswer"].ToString());

                // Final Clue
                xmlTextWriter.WriteElementString("FinalClue", dtRow["FinalClue"].ToString());

                // Created Date
                xmlTextWriter.WriteElementString("CreatedDate", dtRow["CreatedDate"].ToString());

                xmlTextWriter.WriteEndElement();

                #endregion
            }
            xmlTextWriter.WriteEndElement(); // end Treasure

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
            stringWriter.Flush();
            stringWriter.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return stringWriter.ToString();
    }
    #endregion

}
